package org.jiuling.aliyun.sms.convert;

import org.jiuling.aliyun.sms.model.QuerySendStatisticsResponseModel;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 阿里云发送短信查询响应转换
 * @author 紫灵
 * @date 2023年02月10日 11时25分52秒
 */
public class QuerySendStatisticsResponseConvert {

    /** 私有构造方法，禁止创建对象 */
    private QuerySendStatisticsResponseConvert() {
    }

    /**
     * 内容转模型
     * @param querySendStatisticsResponseBody 阿里云发送短信查询响应内容
     * @return 阿里云发送短信查询响应模型
     */
    public static QuerySendStatisticsResponseModel bodyToModel(com.aliyun.sdk.service.dysmsapi20170525.models.QuerySendStatisticsResponseBody querySendStatisticsResponseBody){
        QuerySendStatisticsResponseModel querySendStatisticsResponseModel = new QuerySendStatisticsResponseModel();
        querySendStatisticsResponseModel.setRequestId(querySendStatisticsResponseBody.getRequestId());
        querySendStatisticsResponseModel.setCode(querySendStatisticsResponseBody.getCode());
        querySendStatisticsResponseModel.setMessage(querySendStatisticsResponseBody.getMessage());

        // 封装内容
        QuerySendStatisticsResponseModel.BodyModel bodyModel = new QuerySendStatisticsResponseModel.BodyModel();
        bodyModel.setTotalSize(querySendStatisticsResponseBody.getData().getTotalSize());

        // 封装目标
        List<QuerySendStatisticsResponseModel.BodyModel.TargetModel> targetList = querySendStatisticsResponseBody.getData().getTargetList().stream().map(target ->{
            QuerySendStatisticsResponseModel.BodyModel.TargetModel targetModel = new QuerySendStatisticsResponseModel.BodyModel.TargetModel();
            targetModel.setTotalCount(target.getTotalCount());
            targetModel.setRespondedSuccessCount(target.getRespondedSuccessCount());
            targetModel.setRespondedFailCount(target.getRespondedFailCount());
            targetModel.setNoRespondedCount(target.getNoRespondedCount());
            targetModel.setSendDate(target.getSendDate());
            return targetModel;
        }).collect(Collectors.toList());

        bodyModel.setTargetList(targetList);

        querySendStatisticsResponseModel.setBody(bodyModel);

        return querySendStatisticsResponseModel;
    }

    /**
     * 内容转模型
     * @param querySendStatisticsResponseBody 阿里云发送短信查询响应内容
     * @return 阿里云发送短信查询响应模型
     */
    public static QuerySendStatisticsResponseModel bodyToModel(com.aliyun.dysmsapi20170525.models.QuerySendStatisticsResponseBody querySendStatisticsResponseBody){
        QuerySendStatisticsResponseModel querySendStatisticsResponseModel = new QuerySendStatisticsResponseModel();
        querySendStatisticsResponseModel.setRequestId(querySendStatisticsResponseBody.getRequestId());
        querySendStatisticsResponseModel.setCode(querySendStatisticsResponseBody.getCode());
        querySendStatisticsResponseModel.setMessage(querySendStatisticsResponseBody.getMessage());

        // 封装内容
        QuerySendStatisticsResponseModel.BodyModel bodyModel = new QuerySendStatisticsResponseModel.BodyModel();
        bodyModel.setTotalSize(querySendStatisticsResponseBody.getData().getTotalSize());

        // 封装目标
        List<QuerySendStatisticsResponseModel.BodyModel.TargetModel> targetList = querySendStatisticsResponseBody.getData().getTargetList().stream().map(target ->{
            QuerySendStatisticsResponseModel.BodyModel.TargetModel targetModel = new QuerySendStatisticsResponseModel.BodyModel.TargetModel();
            targetModel.setTotalCount(target.getTotalCount());
            targetModel.setRespondedSuccessCount(target.getRespondedSuccessCount());
            targetModel.setRespondedFailCount(target.getRespondedFailCount());
            targetModel.setNoRespondedCount(target.getNoRespondedCount());
            targetModel.setSendDate(target.getSendDate());
            return targetModel;
        }).collect(Collectors.toList());

        bodyModel.setTargetList(targetList);

        querySendStatisticsResponseModel.setBody(bodyModel);

        return querySendStatisticsResponseModel;
    }
}
